#ifndef PASSWORD_UTILS_H
#define PASSWORD_UTILS_H

#include <stddef.h> // size_t
#include"logger.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
#include <openssl/rand.h>
#include <errno.h>

#define SALT_LENGTH 8
#define SHA256_DIGEST_LENGTH 32
#define HEX_SHA256_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
#define MAX_PASSWORD_LENGTH 64
#define HEX_SALT_BUFFER_SIZE (SALT_LENGTH * 2 + 1)
#define HEX_HASH_BUFFER_SIZE (SHA256_DIGEST_LENGTH * 2 + 1)

int generate_salt(unsigned char *salt, size_t salt_len);
void salt_to_hex(const unsigned char *salt, size_t salt_len, char *hex_salt, size_t hex_salt_len);
int calculate_sha256(const char *data, size_t data_len, unsigned char *hash);
void hash_to_hex(const unsigned char *hash, size_t hash_len, char *hex_hash, size_t hex_hash_len);
int encrypt_password(const char *password, char *hex_salt_out, size_t hex_salt_out_len, char *hex_hash_out, size_t hex_hash_out_len);
int verify_password(const char *input_password, const char *stored_hex_salt, const char *stored_hex_hash);

#endif // PASSWORD_UTILS_H